//聚服务-服务列表
function jfw_list() {
    let mockData = Mock.mock({
        'list|8': [{
            'img': '@image(285x285, #FFC0CB)',
            'title': '@ctitle(10, 15)',
            'fuwutype': '@ctitle(3)',
            'area': '广东深圳',
            'fabudate': '2017-10-10',
        }],
        'ordertype': [{
            'txt': '全部',
            'val': '0'
        }, {
            'txt': '找设计',
            'val': '1'
        }, {
            'txt': '找打样',
            'val': '2'
        }, {
            'txt': '找款型',
            'val': '3'
        }]
    });
    new Vue({
        el: "#jfw_list",
        data() {
            return {
                'ordertype_cur': 0,
                'crumblist': [{
                    'href': '',
                    'text': '首页'
                }, {
                    'href': '',
                    'text': '聚服务'
                }, {
                    'href': '',
                    'text': '服务列表'
                }],
                loginName: '',
                list: [],
                total: 0,
                pageNo: 1,
                typeId: 0,
                areaId: 0,
                typeList: [],
                areaList: []
            }
        },
        methods: {
            getData() {
                let describe = window.location.href.split("?")[1];
                this.loginName = urlParam.loginName();
                var that = this;
                axios.get(urlParam.domain() + '/api/service/demand/list', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: 16,
                        orderType: that.typeId,
                        area: that.areaId,
                        describe: describe
                    }
                })
                    .then(function (response) {
                        that.list = response.data.data.pageData.list;
                        that.total = getPageCount(response.data.data.pageData.total, 15);
                        that.typeList = response.data.data.typeList;
                        that.areaList = response.data.data.areaList;
                        console.log(that.list);
                    });
                this.ordertype = mockData.ordertype;
            },

            getListByType: function (val) {
                if (typeof(val) != 'undefined') {
                    this.typeId = val;
                }
                this.getData();
            },

            getListByArea: function () {
                this.getData();
            },

            listen: function (data) {
                // 翻页事件
                //alert('当前页码：' + data);
                this.pageNo = data;
                this.getData();
            },
        },
        created() {
            this.getData();
        }
    });
}

//聚服务-报价详情
function jfw_baojia() {
    let mockData = Mock.mock({
        'sjinfo': {
            'logo': '@image(80x80, #FFC0CB)',
            'name': '@ctitle(5, 10)',
            'star|0-5': 3,
            'title': '@ctitle(5, 10)',
            'fabudate': '2017-10-20',
            'enddate': '',
            'fuwutype': '找打样',
            'diqu': '全国',
            'maijialist|6': [{
                'img': '@image(60x60, #FFC0CB)'
            }],
            'buchong': '@ctitle(25, 40)',
            'miaohsulist|4': [{
                'img': '@image(150x150, #FFC0CB)'
            }],
            'arealist': [{
                'area': '全国',
                'val': '0'
            }, {
                'area': '江浙沪',
                'val': '1'
            }, {
                'area': '华东区',
                'val': '3'
            }, {
                'area': '华南区',
                'val': '4'
            }],
        },
    });
    new Vue({
        el: "#jfw_baojia",
        data() {
            return {
                'crumblist': [{
                    'href': '',
                    'text': '首页'
                }, {
                    'href': '',
                    'text': '聚服务'
                }, {
                    'href': '',
                    'text': '服务列表'
                }, {
                    'href': '',
                    'text': '普通针织薄料服装'
                }],

                factoryname: null, //工厂名称
                diqu: null, //所在地区
                zhouqi: null, //服务周期
                zongjia: null, //预计总价
                mark: null, //附加说明
                demandId: '',
                demand: '',
                demandQuotationList: '',
                companyInfo: '',
                buyUserInfo: '',
                isCompany: false
            }
        },
        methods: {
            getData() {
                let href = window.location.href;
                let split = href.split("?");
                this.demandId = split[1];
                let that = this;

                axios.get(urlParam.domain() + '/api/service/demandquotation/detail', {
                    params: {
                        id: this.demandId,
                        token: urlParam.token()
                    }
                }).then(function (response) {
                    console.log(response.data);
                    that.demand = response.data.data.demand;
                    that.companyInfo = response.data.data.companyInfo;
                    that.buyUserInfo = response.data.data.buyUserInfo;
                    that.demandQuotationList = response.data.data.demandQuotationList;
                    if (that.companyInfo.id != null) {
                        that.isCompany = true;
                    }

                    console.log(that.buyUserInfo);
                });
                this.sjinfo = mockData.sjinfo;
            },
            submitQuotation: function () {
                if (this.zhouqi == null || this.zongjia == null) {
                    this.$notify.error({
                        title: '错误',
                        message: '服务周期、预计总价不可为空'
                    });
                    return;
                } else if (this.mark == null || this.mark == '') {
                    this.$notify.error({
                        title: '错误',
                        message: '请填写附加说明'
                    });
                    return;
                } else {
                    axios.get(urlParam.domain() + '/api/service/demandquotation/add', {
                        params: {
                            token: urlParam.token(),
                            companyId: this.companyInfo.id,
                            companyName: this.companyInfo.name,
                            demandId: this.demand.id,
                            period: this.zhouqi,
                            remarks: this.mark,
                            total: this.zongjia
                        }
                    })
                        .then(function (response) {
                            console.log(response);
                            this.$notify({
                                title: '成功',
                                message: '报价成功',
                                type: 'success'
                            });
                        });
                }
            }
        },
        created() {
            this.getData();
        }
    });
}

//聚服务-发布需求
function jfw_fabuxuqiu() {
    new Vue({
        el: "#jfw_fabuxuqiu",
        data() {
            return {
                rules: {
                    deadline: [
                        {type: 'date', required: true, message: '请选择日期', trigger: 'change'}
                    ]
                },
                labelPosition: 'top',
                activeName: '1',
                endDate: null,
                mark: null, //详细说明
                area: [],
                diqu: 0, //所在地区
                diquName: '',
                demand: {
                    categoryId: '0',
                    diquName: '',
                    area: '0',
                    deadline: '',
                    describe: '',
                    picList: [],
                    designerId: -1,
                },
                logoUrl: {
                    base64: [""], // base64码
                    url: [""], //最后ajax提交表单信息时，提交的url路径，这个是单张图片上传完毕后台返回的url路径
                }
            }
        },
        methods: {
            getData() {
                let that = this;
                axios.get(urlParam.domain() + '/api/service/demand/show', {
                    params: {
                        token: urlParam.token(),
                    }
                })
                    .then(function (response) {
                        that.area = response.data.data;
                        console.log(that.area);
                    });
            },
            chooseDiqu(val, diquName) {
                this.demand.area = val;
                this.demand.diquName = diquName;
            },

            submitForm(formName, demandType) {
                let that = this;
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        that.demand.categoryId = demandType;
                        if ('0' == that.demand.diqu) {
                            this.$message({
                                message: '请选择地区',
                                type: 'warning'
                            });
                        }
                        for (let url of that.logoUrl.url) {
                            var obj = {};
                            obj.fileUrl = url;
                            this.demand.picList.push(obj);
                        }

                        that.demand.deadline = formatNormal(that.demand.deadline, 0);
                        axios.post(
                            urlParam.domain() + '/api/service/demand/pcAdd',
                            JSON.stringify(that.demand),
                            {headers: {"token": urlParam.token(), "Content-Type": "application/json"}}
                        ).then(result => {
                            console.log(result);
                            that.$message('发布成功');
                            // window.location.href="../jfuwu/list.html";
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            handleClick() {

            }
        },
        created() {
            let urlparams = globalAPI.getRequest();
            this.demand.designerId = urlparams.designerId;
            // console.log("urlParmams :"+(this.demand));
            this.getData();
        },

    });
}